﻿using System;
using System.Collections.Generic;

namespace SBPweb.Modules.Communication
{
	/// <summary>
	/// Class of MessageQueueBase
	/// </summary>
    public abstract class MessageQueueBase : Queue<IMessage>//<T> : Queue<T>, IMessageQueue where T : IMessage
    {
        #region Constructor logic

		/// <summary>
		/// Constructor of MessageQueueBase
		/// </summary>
        protected MessageQueueBase()
        {

        }

        #endregion

        #region Event handlers

		/// <summary>
		/// Event for enqueued
		/// </summary>
        public event EventHandler<MessageEventArgs> Enqueued;
		/// <summary>
		/// Event for dequeues
		/// </summary>
        public event EventHandler<MessageEventArgs> Dequeued;
		/// <summary>
		/// Event for peeked
		/// </summary>
        public event EventHandler<MessageEventArgs> Peeked;

        #endregion

        #region Methods

		/// <summary>
		/// Enqueue message
		/// </summary>
		/// <param name="message">message</param>
        public new void Enqueue(IMessage message)
        {
            base.Enqueue(/*(T)*/message);
            if (Enqueued != null)
            {
                Enqueued(this, new MessageEventArgs(message));
            }
        }

		/// <summary>
		/// Dequeue message
		/// </summary>
		/// <returns>message</returns>
        public new IMessage Dequeue()
        {
            IMessage ret = /*(T)*/base.Dequeue();
            if (Dequeued != null)
            {
                Dequeued(this, new MessageEventArgs(ret));
            }
            return ret;
        }

		/// <summary>
		/// Peek message
		/// </summary>
		/// <returns>message</returns>
        public new IMessage Peek()
        {
            IMessage ret = /*(T)*/base.Peek();
            if (Peeked != null)
            {
                Peeked(this, new MessageEventArgs(ret));
            }
            return ret;
        }

        #endregion
    }
}